import { useEffect, useState } from "react";
import XzqhHandle from "../../../../../../utils/apis/XzqhHandle";
import { Button, Form, Input, Table, Card,DatePicker } from 'antd';
import TextArea from "antd/es/input/TextArea";
import FetchHelper from "../../../../../../utils/helper/fetch-helper";
import { useHistory } from "react-router-dom/cjs/react-router-dom.min";


export default function XzqhAdd() {
    const [xzqhAddDynamicForms, setXzqhAddDynamicForms] = useState();
    const [params, setParams] = useState();
    const { form } = Form.useForm();
    const history = useHistory();
    useEffect(() => {
        XzqhHandle.xzqhAddDynamicApi().then(datas => {
            // console.log(datas)
            setXzqhAddDynamicForms(datas)
        })
    }, [])

    //完成提交
    const onFinish = (values) => {

        FetchHelper.postJson(`/admin-api/ybyj/xzqh`, values).then(alert('新增成功！')).catch(err => alert("保存失败") + err)
    }
    //取消修改
    const quxiaoHandle = () => {
        history.push(`/manager/xzqh`)
    }
    return <>
        <Card className='h100 fill' style={{
            overflow: "scroll"
        }}>
            <Form method="post"
                onFinish={onFinish}
                form={form}
                className="layout-v fill">
                <header style={{
                    fontSize: 20,
                    fontWeight: "bold"
                }}>行政区划新增</header>
                <hr />


                <div className="InputForm" style={{
                    flex: "flex",
                    flexWrap: "wrap"
                }}>
                    {xzqhAddDynamicForms !== undefined && xzqhAddDynamicForms.map(formItem => {
                        let node;
                        switch (formItem.type) {
                            case 'Textarea':
                                node = <TextArea></TextArea>;
                                break;
                            case 'datePicker':
                                node = <><DatePicker
                                    showTime
                                    format="YYYY-MM-DD HH:mm:ss"
                                //placeholder={field.alias} 
                                /></>;
                                break;
                            case 'input':
                            default:
                                node = <Input style={{
                                    width: '90%'
                                }}


                                />
                        }

                        return <div style={{
                            flexBasis: "33%",
                            marginBottom: "10px"
                        }}><Form.Item
                            label={formItem.alias}
                            name={formItem.name}
                        // rules={[{
                        //     required: true
                        // }]}
                        >{node}</Form.Item></div>
                    })}
                </div>
                <div className="layout-h">
                    <Button className="btn1" type="primary" htmlType="submit" >保存</Button>
                    <Button onClick={quxiaoHandle} className="btn2">返回</Button>
                </div>

            </Form>
        </Card>
    </>
}